<?php
require_once 'IEngine.php';

class YahooEngine implements IEngine {
	private $tags = array("Web");
	private $name = "Yahoo!";

	public function getTags() {
		return $this->tags;
	}

	public function getName() {
		return $this->name;
	}

	public function search($term) {
		$results = array();
		$url = "http://search.yahoo.com/search?ei=UTF-8&p=" . urlencode($term);
		$str = file_get_contents($url);
		$page = str_get_html($str);
		$res = $page->find("div#web > ol > li");
		$res = $res;
		//$res-> children  = $res->nodes = $res->parent = 'none';
		//print_r($res);
		foreach ($res as $child) {
			$result = array();
			$title = $child->find("h3 a");
			if (count($title) == 0 || !isset($title[0]->attr['class'])) continue;
			$result['title'] = $title[0]->innertext();
			$result['href'] = $title[0]->attr['href'];
			$description = $child->find("div.sm-abs");
			if (!count($description)) {
				$description = $child->find("div.abstr");
				if (!count($description)) {
					continue;
				}
			}
			$result['description'] = $description[0]->innertext();
			//$results[] = $child->innertext();//htmlentities($child->innertext());
			$results[] = $result;
		}
		return $results;
	}

	public function engineLogo() {
		return '<img class="enginelogo" src="http://js.careerage.com/images/yahoo-logo.gif" />';
	}
}